Skip to content

feat: add Text-to-Speech (speaker) button to read chatbot responses aloud #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Anujjoshi3105
Copy link

Summary

This pull request implements the Text-to-Speech functionality as described by me in Issue #309. It introduces a speaker icon next to each bot response, allowing users to listen to the chatbot's message using the browser's native SpeechSynthesis API.


Implementation Details

  • Added a speaker button next to feedback buttons for bot messages
  • On click, the message is spoken aloud using window.speechSynthesis
  • Includes basic controls to start and stop speech
  • Non-intrusive: speech playback is optional and user-triggered
  • Minimal changes to the existing UI structure

Preview

Screenshot 2025-07-24 164151

Benefits

  • Enhances accessibility for visually impaired users
  • Improves multitasking experience (hands-free interaction)
  • Light-weight: relies only on built-in browser APIs (no external dependency)

@toi500
Copy link
Contributor

toi500 commented Jul 24, 2025

This is great. Just tested and it works for me. But I have noticed that it only shows if feedback is enable. Is that correct?

image

Just make sure to add it like this in the README (don't use ; use ,).

            ttsConfig: {
                language: 'en-US',
                voice: 'Google UK English Male', 
                rate: 1,
                pitch: 1,
                volume: 1,
            }

Edit:

I left my testing script here if someone wants to test this out too:

<script type="module">
    import Chatbot from "https://cdn.jsdelivr.net/gh/Anujjoshi3105/FlowiseChatEmbed@feat/text-to-speech-support/dist/web.js"
    Chatbot.init({
        chatflowid: "xxxxxxxxxx",
        apiHost: "xxxxxxxxx",
        theme: {
            ttsConfig: {
                language: 'en-US',
                voice: 'Google UK English Male',
                rate: 1,
                pitch: 1,
                volume: 1,
            }
        }
    })
</script>

@Anujjoshi3105
Copy link
Author

Anujjoshi3105 commented Jul 24, 2025

Yes, currently the speaker icon only shows if feedback is enabled. Should l make a small update so that it can be toggled independently using a ttsConfig.enabled flag — that way it won't depend on feedback visibility.

Also noted that the Play and Pause icon color for new TTS Button doesn’t update when the feedback color changes — I’ll fix that as well. I plan to complete these changes by tomorrow.

@toi500
Copy link
Contributor

toi500 commented Jul 24, 2025

I am just pointing it out, as it was confusing to me why it wasn't showing until I realized about the feedback. I would hold that change until the maintainer has something to say about this; maybe they want it like that.

In relation to the color update, that would definitely be nice to have fixed.

@Anujjoshi3105
Copy link
Author

I suggest adding a dropdown at the top of the title bar to select the browser-supported language and speaker (instead harcoding in ttsConfig). However, I’d prefer to proceed with this based on the maintainer’s guidance and requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants